package drawing 
{
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	import furnitures.FurnitureModel;
	import resources.IBitmapDataProvider;
	import utils.Logger;
	/**
	 * ...
	 * @author Dmitriy Gaiduk
	 */
	public class BitmapKitPalette implements IPaletteDisposable
	{
		private var _bitmapDataProvider:IBitmapDataProvider;
		
		private var _repeatBitmap:Boolean = false;
		private var _smooth:Boolean = true;
		
		
		public function BitmapKitPalette(bitmapDataProvider:IBitmapDataProvider) 
		{
			_bitmapDataProvider = bitmapDataProvider;
		}
		
		/* INTERFACE draw.IPalette */
		
		public function beginFill(surface:Graphics, brushType:String, 
									surfaceWidth:Number, 
									surfaceHeight:Number,
									reverseByX:Boolean = false,
									reverseByY:Boolean = false):Boolean 
		{
			switch(brushType) {
				case FurnitureModel.EXTRA_GRID:
				case FurnitureModel.EXTRA_GLASS:
						return false;
					break;

			}
			
			var bmData:BitmapData = _bitmapDataProvider.getBitmapData(brushType);
			if (bmData == null)
			{
				var noImageMov:Sprite = new NoImageMovie();
				bmData = new BitmapData(noImageMov.width, noImageMov.height, true, 0xFF0000);
				bmData.draw(noImageMov, null, null, null, null, true);
				//return false;
			}
			var matr:Matrix = new Matrix();
			var scaleX:Number = surfaceWidth / bmData.width;
			var scaleY:Number = surfaceHeight / bmData.height;
			
			
			if (reverseByX)
			{
				scaleX = - scaleX;
				matr.tx = - bmData.width;
				
			}
			if (reverseByY)
			{
				scaleY = - scaleY;
				matr.ty = surfaceHeight / bmData.height * surfaceHeight;
				
			}
			
			matr.scale(scaleX, scaleY);
			
			surface.beginBitmapFill(bmData,
									matr,
									_repeatBitmap,
									_smooth);
			return true;
		}
		
		public function endFill(surface:Graphics):void 
		{
			surface.endFill();
		}
		
		public function lineStyle(surface:Graphics):Boolean
		{
			return false;
		}
		
		
		public function get repeatBitmap():Boolean 
		{
			return _repeatBitmap;
		}
		
		public function set repeatBitmap(value:Boolean):void 
		{
			_repeatBitmap = value;
		}
		
		public function get smooth():Boolean 
		{
			return _smooth;
		}
		
		public function set smooth(value:Boolean):void 
		{
			_smooth = value;
		}
		
		public function get bitmapDataProvider():IBitmapDataProvider 
		{
			return _bitmapDataProvider;
		}
		
		
		private function log(msg:String):void
		{
			Logger.log(this, msg);
		}
		
		public function dispose():void
		{
			
		}
		
	}

}